package com.study.example.gameserver.module.buff.service;

import com.sparrow.common.buff.BuffBox;
import com.sparrow.common.buff.context.DefaultBuffContext;
import com.sparrow.common.buff.domain.Buff;
import com.sparrow.common.buff.domain.IBuffActor;
import com.study.example.gameserver.module.buff.manager.BuffManager;
import com.study.example.gameserver.module.player.entity.Player;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class BuffService {

    @Autowired
    BuffManager buffManager;

    public void addBuff(Player player, int buffId) {
        addBuff(player.getBuffBox(), player, player, buffId);
    }

    public void addBuff(BuffBox buffBox, IBuffActor source, IBuffActor target, int buffId) {
        Buff buff = buffManager.createBuff(buffId);
        DefaultBuffContext buffContext = new DefaultBuffContext();
        buffContext.setSource(source);
        buffContext.setTarget(target);
        buff.setBuffContext(buffContext);
        buffBox.addBuff(buff);
    }

}
